package com.exam.lenovo;

import java.util.Scanner;

/**
 * date:
 * description:
 */
public class Solution01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        for (int i = 0; i < num; i++) {
            int a1 = scanner.nextInt();
            int b1 = scanner.nextInt();
            int c1 = scanner.nextInt();
            int a2 = scanner.nextInt();
            int b2 = scanner.nextInt();
            int c2 = scanner.nextInt();
            int num1 = c1 / a1;
            if(c1 % a1 != 0) {
                num1++;
            }
            int num2 = c2 / a2;
            if(c2 % a2 != 0) {
                num2++;
            }
            if(num1 * b1 < num2 * b2){
                System.out.println("A");
            } else if(num1 * b1 > num2 * b2) {
                System.out.println("B");
            } else{
                System.out.println("A&B");
            }
        }
    }

}
